package com.example.logistics_oa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.comment_oa.pojos.SalaryReview;
import com.example.logistics_oa.controller.util.GetDate;
import com.example.logistics_oa.service.SalaryReviewService;
import com.example.logistics_oa.mapper.SalaryReviewMapper;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
* @author 安徽彭于晏
* @description 针对表【salary_review】的数据库操作Service实现
* @createDate 2022-10-15 10:17:19
*/
@Service
public class SalaryReviewServiceImpl extends ServiceImpl<SalaryReviewMapper, SalaryReview>
    implements SalaryReviewService{

    @Autowired
    SalaryReviewMapper salaryReviewMapper;

    @Override
    public Boolean selectAllByDate() {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");


        SalaryReview salaryReview = salaryReviewMapper.selectAllByDate();
        GetDate getDate = new GetDate();
        String thisDay = getDate.getThisDay();
        System.err.println("这个月第一天"+thisDay);
        String nextDay = getDate.getNextDay(salaryReview.getSrDate());
        System.err.println("查询出来上次发工资的日期，他的下个月的第一天"+nextDay);

        //这里说明 如果 上次发工资的日期的下个月的第一天，和这个月相同，就证明，不能再发工资了
        //
        if(thisDay.equals(nextDay)){
            System.out.println(thisDay.equals(nextDay));
            return true;
        }else {
            System.out.println(thisDay.equals(nextDay));
            return  false;
        }

    }

    @Override
    public SalaryReview chakan() {
        return salaryReviewMapper.chakan();
    }


    @Override
    public void insertAll(SalaryReview salaryReview) {

        GetDate getDate = new GetDate();
        String nextDay = getDate.getNextDay(salaryReview.getSrDate());
        salaryReview.setSrId("SH"+nextDay);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = null;
        try {
            parse = simpleDateFormat.parse(nextDay);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.err.println(parse);
        salaryReview.setSrDate(parse);
        salaryReviewMapper.insertAll(salaryReview);
    }



}




